/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Andre
 */
@Entity
@Table(name = "matricula")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Matricula.findAll", query = "SELECT m FROM Matricula m"),
    @NamedQuery(name = "Matricula.findByIdMatricula", query = "SELECT m FROM Matricula m WHERE m.idMatricula = :idMatricula"),
    @NamedQuery(name = "Matricula.findByDataInicio", query = "SELECT m FROM Matricula m WHERE m.dataInicio = :dataInicio"),
    @NamedQuery(name = "Matricula.findByDataFim", query = "SELECT m FROM Matricula m WHERE m.dataFim = :dataFim"),
    @NamedQuery(name = "Matricula.findByContrato", query = "SELECT m FROM Matricula m WHERE m.contrato = :contrato")})
public class Matricula implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idMatricula")
    private Integer idMatricula;
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "meses")
    private Integer meses;
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "dataInicio")
    @Temporal(TemporalType.DATE)
    private Date dataInicio;
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "dataFim")
    @Temporal(TemporalType.DATE)
    private Date dataFim;
    
    @JoinColumn(name = "idSituacao", referencedColumnName = "idSituacao")
    @ManyToOne(optional = false)
    private Situacao situacao;
    
    @JoinColumn(name = "idAluno", referencedColumnName = "idPessoa")
    @ManyToOne(optional = false)
    private Aluno aluno;
    
    @JoinColumn(name = "idTurma", referencedColumnName = "idTurma")
    @ManyToOne(optional = false)
    private Turma turma;
    
    
    @JoinColumn(name = "idContrato", referencedColumnName = "idContrato")
    @ManyToOne(optional = false)
    private Contrato contrato;
    
    @Transient
    private double valorTotal;

    public Matricula() {
    }

    public Matricula(Date dataInicio, Date dataFim) {
        this.dataInicio = dataInicio;
        this.dataFim = dataFim;
    }

    public Integer getIdMatricula() {
        return idMatricula;
    }

    public Date getDataInicio() {
        return dataInicio;
    }

    public void setDataInicio(Date dataInicio) {
        this.dataInicio = dataInicio;
    }

    public Date getDataFim() {
        return dataFim;
    }

    public void setDataFim(Date dataFim) {
        this.dataFim = dataFim;
    }

    public Situacao getSituacao() {
        return situacao;
    }

    public void setSituacao(Situacao situacao) {
        this.situacao = situacao;
    }

    public Aluno getAluno() {
        return aluno;
    }

    public void setAluno(Aluno aluno) {
        this.aluno = aluno;
    }

    public Turma getTurma() {
        return turma;
    }

    public void setTurma(Turma turma) {
        this.turma = turma;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idMatricula != null ? idMatricula.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Matricula)) {
            return false;
        }
        Matricula other = (Matricula) object;
        if ((this.idMatricula == null && other.idMatricula != null) || (this.idMatricula != null && !this.idMatricula.equals(other.idMatricula))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "modelo.Matricula[ idMatricula=" + idMatricula + " ]";
    }

    public Contrato getContrato() {
        return contrato;
    }

    public void setContrato(Contrato contrato) {
        this.contrato = contrato;
    }

    @XmlTransient
    public double getValorTotal() {
        return meses * turma.getModalidade().getValor();
    }

    public Integer getMeses() {
        return meses;
    }

    public void setMeses(Integer meses) {
        this.meses = meses;
    }
    
}
